#ifndef FND_GROUP_MAP_HPP
#define FND_GROUP_MAP_HPP
#include "page_property_map.hpp"
namespace FndGame2D {
    class group_page_property_map {
    public:
        typedef std::map<std::string, page_property_map> group_page_type ;
    private:
        group_page_type m_values ;
    public:
        bool add_page(const char* page_file_name, const std::string& page_name) {
            return m_values[page_name].load_info_from_file(page_file_name) ;
        }
        template<typename T>
        T get_value(const std::string& page,
                    const std::string& head,
                    const std::string& key,
                    T value_if_not_found = T()) {
            if(m_values.find(page) == m_values.end()) {
                pantheios::log_DEBUG(page, " not exist\n" ) ;
                return false ;
            }
            return m_values[page].get_value<T>(head, key, value_if_not_found) ;
        }
        template<typename T>
        bool set_value(const std::string& page,
                       const std::string& head,
                       const std::string& key,
                       const T& value,
                       bool changed_if_found = false) {
            if(m_values.find(page) == m_values.end()) {
                pantheios::log_DEBUG(page, " not found\n") ;
                return false ;
            }
            return  m_values[page].set_value<T>(head,
                                                key,
                                                value,
                                                changed_if_found) ;
        }
        bool remove_page(const std::string& page) {
            return m_values.erase(page) ;
        }

        bool remove_head(const std::string& page, const std::string head) {
            if(m_values.find(page) == m_values.end()) {
                pantheios::log_DEBUG(page, " does not exist(remove_head)\n") ;
                return false ;
            }
            return m_values[page].remove_key(head) ;
        }
        bool remove_value(const std::string& page,
                          const std::string& head,
                          const std::string& key) {
            if(m_values.find(page) == m_values.end()) {
                pantheios::log_DEBUG(page, " does not exist(remove_value)\n") ;
                return false ;
            } else
                return m_values[page].remove_group(head, group) ;
        }
        void save_page_to_file(const std::string& page,
                               const char* file_name) {
            if(m_values.find(page) == m_values.end()) {
                pantheios::log_DEBUG(page, " does not exists. don't save to ",
                                     file_name) ;
            }
            m_values[page].save_info_to_file(file_name) ;
        }
    } ;
}
#endif  // FND_GROUP_MAP_HPP
